package org.otherworld.command;

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Iterator;

import org.otherworld.process.SystemInfoUtils;
import org.otherworld.process.WindowsDXGraphicsInfo;
import org.otherworld.property.PropertyLoader;

public class Display extends Command{

	public Display() throws Exception{
		super();
	}
	
	public String getCommand() {
		return "display";
	}

	public ArrayList<String> getConnectors() {
		ArrayList<String> connectors = new ArrayList<String>();
		connectors.add("system");
		connectors.add("directx");
		connectors.add("memory");
		connectors.add("processor");
		connectors.add("hdd");
		connectors.add("user");
		return connectors;
	}
	
	public boolean run(String command) throws Exception{
		String[] commandSplit = command.split(" ");
		if (commandSplit.length > 3 || commandSplit.length < 2) {
			return false;
		}
		
		
		
		if (commandSplit[0].equals(this.getCommand())) {
			
			ArrayList<String> connectors = this.getConnectors();

				int con = this.getConnectorID(connectors, command);
				SystemInfoUtils sysinfo = new SystemInfoUtils();

				
				switch (con) {
				case -1:
					System.out.println("Unrecognized parameter. You can use the following: ");
					for (int i = 0; i < connectors.size(); ++i) {
						System.out.print(connectors.get(i) + ", ");
					}
					System.out.println(" ");
					return false;
				case 0:
					sysinfo.displayFullSystemInformation();
					return true;
				case 1:
					WindowsDXGraphicsInfo gr = new WindowsDXGraphicsInfo();
					PropertyLoader loader = new PropertyLoader();
					Hashtable<String, Object> sys = loader.getSystemProperties();
					String tempDir = sys.get("sys_temp").toString();
					String output = sys.get("sys_dxdiag_output").toString();
					String commandT = sys.get("sys_dxdiag_command") + tempDir + output;
					WindowsDXGraphicsInfo w = new WindowsDXGraphicsInfo();
					w.init(commandT,tempDir, output);
					Hashtable<String, String> sysparams = w.getDXInfo();
					Iterator<String> iter = sysparams.keySet().iterator();
					while (iter.hasNext()) {
						String key = iter.next();
						String value = sysparams.get(key);
						System.out.println(key + " - " + value);
					}
					return true;
				case 2:
					sysinfo.displayMemoryInformation();
					return true;
				case 3:
					sysinfo.displayProcessorCount();
					return true;
				case 4:
					sysinfo.displayHardDriveInformation();
					return true;
				}
				
				
			

		}
		return false;
	}

	
}
